#include <stdio.h>
typedef unsigned long NUM;

int main()
{
	NUM factorial[10] = {1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880};
	NUM result = 0, i;

	for (i = 3; i < 2540160; i++) // 362880*7 :: 9! * digits
	{
		NUM sum = 0, j;
		for (j = i; j; j /= 10)
			sum += factorial[j % 10];

		if (sum == i)
			result += i;
	}

	printf("Result: %u\n", result);
	return 0;
}
